package com.crm.controller;

import com.crm.base.BaseController;
import com.crm.domain.vo.ModuleTreeVO;
import com.crm.domain.entity.Module;
import com.crm.domain.entity.User;
import com.crm.domain.vo.MenuTreeVO;
import com.crm.service.ModuleService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 模块控制器
 */

@RestController
@RequestMapping("/module")
public class ModuleController extends BaseController<ModuleService, Module> {


    // 查询菜单树
    @RequestMapping("/findMenu")
    public List<MenuTreeVO> findMenu(HttpSession session, HttpServletResponse response) throws Exception {
        User u = (User) session.getAttribute("session_user");
        if (u != null) {
            //return service.findModuleByUid(u.getId(), "3");
            return baseService.getMenu(u.getId());
        } else {
            response.sendRedirect("/page/login");
            return null;
        }
    }

    // 查询角色权限
    @RequestMapping("/findModuleByRoleId")
    public List<Integer> findModuleByRoleId(Integer roleId) {
        return baseService.getModuleByRoleId(roleId);
    }

    // 查询权限树
    @RequestMapping("/getModule")
    public List<ModuleTreeVO> getModule() {
        return baseService.findModule();
    }

}
